package com.sky.mapper;

import com.sky.entity.AddressBook;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * @author admin
 * @date 2024/9/18
 */
@Mapper
public interface AddressBookMapper {

    /**
     * 新增地址
     * @param addressBook
     */
    void add(AddressBook addressBook);

    @Select("select * from address_book where user_id=#{userId}")
    List<AddressBook> list(Long userId);

    /**
     * 根据id, 默认地址，userId查询地址
     * @param addressBook
     * @return
     */
    AddressBook getAddressBook(AddressBook addressBook);

    /**
     * 修改地址
     * @param addressBook
     */
    void update(AddressBook addressBook);

    /**
     * 删除地址
     * @param addressBook
     */
    @Delete("delete from address_book where user_id=#{userId} and id=#{id}")
    void delete(AddressBook addressBook);

    /**
     * 设置全部地址为非默认地址
     * @param addressBook
     */
    @Update("update address_book set is_default=#{isDefault} where user_id=#{userId}")
    void updateDefaultByUserId(AddressBook addressBook);
}
